package jsu.lipengcheng.trafficnet.Ai;

import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Aiconfig {
    @Autowired
    private SqlChatMemoryStores sqlChatMemoryStores;
    //构建ChatMemoryProvider对象
    @Bean
    public ChatMemoryProvider chatMemoryProvider(){
        ChatMemoryProvider chatMemoryProvider = new ChatMemoryProvider() {
            @Override
            public ChatMemory get(Object memoryid) {
                MessageWindowChatMemory build = MessageWindowChatMemory.builder()
                        .id(memoryid)
                        .maxMessages(10)
                        .chatMemoryStore(sqlChatMemoryStores)
                        .build();
                return build;
            }
        };
        return chatMemoryProvider;
    }
}

